from PySide2 import QtGui, QtCore, QtWidgets
from PySide2.QtWidgets import *
import sys


class Demo(QWidget):
    def __init__(self, parent=None):
        super(Demo, self).__init__(parent)
        self.initUI()

    def initUI(self):
        form = QFormLayout()
        label1 = QLabel()
        label1.setText("用户名：")
        text1 = QLineEdit()

        label2 = QLabel()
        label2.setText("密码：")

        text2 = QLineEdit()

        btn1 = QPushButton()
        btn1.setText("登录")
        btn2 = QPushButton()
        btn2.setText("取消")

        # 将上面创建的6个控件分为3行添加到表单布局中
        form.addRow(label1, text1)
        # 创建垂直布局管理器
        vlayout = QVBoxLayout()
        vlayout.addWidget(text2)         # 向垂直布局管理器中添加密码输入框
        vlayout.addWidget(QLabel("密码只能输入8位"))
        # 将垂直布局嵌套到表单布局
        form.addRow(label2, vlayout)
        form.addRow(btn1, btn2)
        # 设置表单布局
        self.setLayout(form)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    demo = Demo()
    demo.show()
    sys.exit(app.exec_())

